package tt.dz.egobus.servicemanager.vo;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import tt.dz.egobus.servicemanager.bean.EntityViewVo;
import tt.dz.egobus.servicemanager.entities.BusinessExceptionAlert;

import javax.persistence.Column;

/**
 * @author Anson
 * @date 17-4-17
 * @name 异常上报vos
 * @since 1.0.4
 */
public class BusinessExceptionAlertViewVo implements EntityViewVo<BusinessExceptionAlert, BusinessExceptionAlertViewVo> {

    private static final Logger LOGGER = LoggerFactory.getLogger(BusRegisterServiceViewVo.class);
    private static final long serialVersionUID = 7855581848214614034L;

    @Override
    public BusinessExceptionAlert convert() {
        BusinessExceptionAlert pojo = new BusinessExceptionAlert();
        try {
            BeanUtils.copyProperties(this, pojo);
        } catch (BeansException e) {
            LOGGER.error("BusinessExceptionAlertViewVo -> BusinessExceptionAlert bean拷贝异常, viewVo={}", this, e);
        }
        return pojo;
    }

    @Override
    public BusinessExceptionAlertViewVo view(BusinessExceptionAlert pojo) {
        try {
            BeanUtils.copyProperties(pojo, this);
        } catch (BeansException e) {
            LOGGER.error(" BusinessExceptionAlert ->  BusinessExceptionAlertViewVo bean拷贝异常, viewVo={}", this, e);
        }
        return this;
    }

    private String id;

    /**
     * 司机名称
     */
    @Column(name = "driver_name")
    @NotBlank(message = "司机名称不能为空")
    @Length(max = 50, message = "车牌号长度不能超过50")
    private String driverName;


    /**
     * 手机号码
     */
    @Column(name = "driver_mobile")
    @NotBlank(message = "司机名称不能为空")
    @Length(max = 15, message = "车牌号长度不能超过15")
    private String driverMobile;

    /**
     * 车牌号
     */
    @Column(name = "bus_no")
    @Length(max = 255, message = "车牌号长度不能超过255")
    private String busNo;

    /**
     * 上报地点经度坐标
     */
    @Column(name = "x")
    private double x;

    /**
     * 上报地点纬度坐标
     */
    @Column(name = "y")
    private double y;

    /**
     * 上报的地理位置名称
     */
    @Column(name = "address")
    @Length(max = 255, message = "上报的地理位置名称长度不能超过255")
    private String address;

    /**
     * 异常信息
     */
    @Column(name = "exception")
    @NotBlank(message = "异常信息不能为空")
    @Length(max = 255, message = "异常信息长度不能超过255")
    private String exception;


    /**
     * 异常类型 1:系统 2:APP 3:车辆 4:其他
     */
    private int exceptionType = 0;

    /**
     * 状态 , 0:上报;10:接受;20:正处理;30:处理完毕;40:取消
     */
    private int status = 0;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getDriverName() {
        return driverName;
    }

    public void setDriverName(String driverName) {
        this.driverName = driverName;
    }

    public String getDriverMobile() {
        return driverMobile;
    }

    public void setDriverMobile(String driverMobile) {
        this.driverMobile = driverMobile;
    }

    public String getBusNo() {
        return busNo;
    }

    public void setBusNo(String busNo) {
        this.busNo = busNo;
    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getException() {
        return exception;
    }

    public void setException(String exception) {
        this.exception = exception;
    }

    public int getExceptionType() {
        return exceptionType;
    }

    public void setExceptionType(int exceptionType) {
        this.exceptionType = exceptionType;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof BusinessExceptionAlertViewVo)) return false;

        BusinessExceptionAlertViewVo that = (BusinessExceptionAlertViewVo) o;

        if (Double.compare(that.getX(), getX()) != 0) return false;
        if (Double.compare(that.getY(), getY()) != 0) return false;
        if (getExceptionType() != that.getExceptionType()) return false;
        if (getStatus() != that.getStatus()) return false;
        if (getId() != null ? !getId().equals(that.getId()) : that.getId() != null) return false;
        if (getDriverName() != null ? !getDriverName().equals(that.getDriverName()) : that.getDriverName() != null)
            return false;
        if (getDriverMobile() != null ? !getDriverMobile().equals(that.getDriverMobile()) : that.getDriverMobile() != null)
            return false;
        if (getBusNo() != null ? !getBusNo().equals(that.getBusNo()) : that.getBusNo() != null) return false;
        if (getAddress() != null ? !getAddress().equals(that.getAddress()) : that.getAddress() != null) return false;
        return getException() != null ? getException().equals(that.getException()) : that.getException() == null;

    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = getId() != null ? getId().hashCode() : 0;
        result = 31 * result + (getDriverName() != null ? getDriverName().hashCode() : 0);
        result = 31 * result + (getDriverMobile() != null ? getDriverMobile().hashCode() : 0);
        result = 31 * result + (getBusNo() != null ? getBusNo().hashCode() : 0);
        temp = Double.doubleToLongBits(getX());
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(getY());
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + (getAddress() != null ? getAddress().hashCode() : 0);
        result = 31 * result + (getException() != null ? getException().hashCode() : 0);
        result = 31 * result + getExceptionType();
        result = 31 * result + getStatus();
        return result;
    }

    @Override
    public String toString() {
        return "BusinessExceptionAlertViewVo{" +
                "id='" + id + '\'' +
                ", driverName='" + driverName + '\'' +
                ", driverMobile='" + driverMobile + '\'' +
                ", busNo='" + busNo + '\'' +
                ", x=" + x +
                ", y=" + y +
                ", address='" + address + '\'' +
                ", exception='" + exception + '\'' +
                ", exceptionType=" + exceptionType +
                ", status=" + status +
                '}';
    }
}
